package com.leyou.item.controller;

import com.leyou.common.enums.ExceptionEnum;
import com.leyou.common.exceptions.LyException;
import com.leyou.item.entity.Item;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ItemController {

    /**
     * 保存商品信息
     * ResponseEntity 可以设置状态码
     * @param item
     * @return
     */
    @PostMapping("/item")
    public ResponseEntity<Item> saveItem(Item item){
        if(item.getPrice() == null){
            throw new LyException(ExceptionEnum.PRICE_IS_NULL);
        }
//        模拟保存操作
        item.setId(3);
        return ResponseEntity.ok(item);
    }

    /*
    * spring如果对事物进行控制,对事物进行回滚,默认只能识别runtimeException,
    *
    *
    *
    * */

}
